const fp = require("lodash/fp");
const cars = require("./data.json");

const _average = function (xs) {
  return fp.reduce(fp.add, 0, xs) / xs.length;
};

// const averageDollarValue = function (cars) {
//   const dollar_values = fp.map(function (car) {
//     return car.dollar_value;
//   }, cars);

//   return _average(dollar_values);
// };

// console.log(averageDollarValue(cars));

const calcAveragePrice = fp.flowRight(
  _average,
  fp.map((car) => car.dollar_value)
);

console.log(calcAveragePrice(cars));
